import { history } from 'umi';
import { fetchPageConfig, fetchPageConfigDetail, fakeSavePageConfig } from '@/services/WechatPageServices'
import { notification } from 'antd';
const WechatPage = {
    namespace: 'wechatPage',
    state: {
        pageConfigList: {},
    },
    effects: {
        *fetchPageConfig({ payload, callback }, { call, put }) {
            const response = yield call(fetchPageConfig, payload);
            if (!response) return;
            const { pageConfigList, total } = response.content;
            yield put({
                type: 'save',
                payload: {
                    pageConfigList: {
                        list: pageConfigList,
                        total,
                    },
                },
            });
        },

        *fetchPageConfigDetail({ payload, callback }, { call, put }) {
            const response = yield call(fetchPageConfigDetail, payload);
            if (!response) return;
            const { content } = response
            callback && callback(content)
        },


        *fakeSavePageConfig({ payload, callback }, { call, put }) {
            const response = yield call(fakeSavePageConfig, payload);
            if (!response) return;
            notification.success({
                message: '温馨提示',
                description: `保存成功`,
            });
            callback && callback();
        },


    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload,
            };
        },
    },
}
export default WechatPage